package com.omt.tarjimdinek.domain.member.entity;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.Version;
import javax.validation.constraints.Size;

import org.apache.log4j.Logger;

import com.google.common.base.Objects;
import com.omt.tarjimdinek.domain.islamicLibrary.entity.Sahabi;
import com.omt.tarjimdinek.support.Identifiable;

/**
 * an address
 * @author chabane
 *
 */
@Entity
@Table(name="a01_adr")
public class Adresse implements Identifiable<Long>, Serializable{

    private static final long serialVersionUID = 1L;
    private static final Logger log = Logger.getLogger(Adresse.class);
    
	/** ID SGBD */
	@Column(name="CNADR", length=11)
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long id;
	
	@Column(name = "VERSION", precision = 10)
    @Version
    private Integer version;
	
	/** postal code */
	@Size(max = 5)
	@Column(name="LICP", length=5)
	private String codePostal;
	
	/** city */
	@Size(max = 45)
	@Column(name="LIVIL", length=45)
	private String ville;
	
	/** country */
	@JoinColumn(name = "CNPYS", nullable = false)
	@ManyToOne
	private Pays pays;
	
	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	@Transient
	public boolean isIdSet() {
	    return id != null && id.compareTo(Long.valueOf(0)) != 0;
	}

	/**
	 * @return the version
	 */
	public Integer getVersion() {
		return version;
	}

	/**
	 * @param version the version to set
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}
	
	public String getCodePostal() {
		return codePostal;
	}

	public void setCodePostal(String codePostal) {
		this.codePostal = codePostal;
	}

	public String getVille() {
		return ville;
	}

	public void setVille(String ville) {
		this.ville = ville;
	}

	public Pays getPays() {
		return pays;
	}

	public void setPays(Pays pays) {
		this.pays = pays;
	}

	/**
     * equals implementation using a business key.
     */
    public boolean equals(Object other) {
        return this == other || (other instanceof Sahabi && hashCode() == other.hashCode());
    }

    public int hashCode() {
        int hashCode = Objects.hashCode(getCodePostal());
        hashCode += Objects.hashCode(getVille());
        hashCode += Objects.hashCode(getPays());
        return hashCode;
    }
    
    /**
     * Construct a readable string representation for this instance.
     * @see java.lang.Object#toString()
     */
    public String toString() {
        return Objects.toStringHelper(this) //
                .add("id", getId()) //
                .add("codePostal", getCodePostal()) //
                .add("ville", getVille()) //
                .add("pays", getPays()) //
                .add("version", getVersion()) //
                .toString();
    }

	public void initDefaultValues() {
		// TODO Auto-generated method stub
		
	}
}
